package com.ourway.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.ourway.dtos.UserDTO;
import com.ourway.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 用户 持久层服务
 *
 * @author lwh
 * @date 2021/12/03
 */
@Mapper
public interface UserMapper extends BaseMapper<User>, MPJBaseMapper<User> {

    /**
     * 查询全部
     * @param pageIndex 页数
     * @param pageSize 每页总量
     * @return 用户信息
     */
    @Select("SELECT u1.*, d.name as department_name, u2.name as manager_name FROM `user` u1 " +
            "LEFT JOIN `department` d on u1.department_id = d.department_id " +
            "LEFT JOIN `user` u2 on u1.manager_id = u2.user_id " +
            "ORDER BY u1.user_no " +
            "LIMIT ${(pageIndex - 1) * pageSize}, #{pageSize}")
    List<UserDTO> findAll(@Param("pageIndex") int pageIndex, @Param("pageSize") int pageSize);
}
